package com.inspur.edp.bff.spi.assembler;

import com.inspur.edp.bff.api.manager.IFSManagerContext;
import com.inspur.edp.bff.api.manager.assembler.IExtendRetrieveDefaultChildAssembler;
import com.inspur.edp.bff.api.manager.context.RetrieveDefaultChildContext;
import com.inspur.edp.bff.spi.action.retrievedefault.AbstractRetrieveDefaultChildAction;

import java.util.List;

public abstract class AbstractRetrieveDefaultChildAssembler implements
        IExtendRetrieveDefaultChildAssembler {

    protected List<AbstractRetrieveDefaultChildAction> getRetrieveDefaultActions(
            RetrieveDefaultChildContext createContext) {
        return null;
    }

    @Override
    public final void doBeforeRetrieveDefault(IFSManagerContext context,
                                              RetrieveDefaultChildContext createContext) {
    }

    @Override
    public final void doRetrieveDefault(IFSManagerContext context,
                                        RetrieveDefaultChildContext createContext) {
        List<AbstractRetrieveDefaultChildAction> actions = getRetrieveDefaultActions(createContext);
        if (actions == null || actions.isEmpty()) {
            return;
        }

        dealRetrieveDefault(actions, context, createContext);
    }

    private final void dealRetrieveDefault(List<AbstractRetrieveDefaultChildAction> actions,
                                           IFSManagerContext context, RetrieveDefaultChildContext createContext) {
        for (AbstractRetrieveDefaultChildAction action : actions) {
            action.deal(context);
        }
    }

    @Override
    public final void doAfterRetrieveDefault(IFSManagerContext context,
                                             RetrieveDefaultChildContext createContext) {
    }
}
